package com.wandian.ui.controls
{
	import flash.events.FocusEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import com.wandian.ui.skins.Skin;


	public class Label extends UIComponent
	{
		protected var textField:TextField
		protected var textFormat:TextFormat
		protected var skin:Skin;

		public function Label(w:int=100, h:int=30)
		{
			super(w, h);

		}

		override protected function createChildren():void
		{
			super.createChildren()
			var skinClass:Class=this.getStyle("skin") as Class
			skin=new skinClass() as Skin
			skin.styleClient=this
			this.addChild(skin);
			textField=new TextField();
			//textField.border=true;
			textField.selectable=false;
			textFormat=new TextFormat();
			textFormat.size=getStyle("fontSize")
			textFormat.font=getStyle("fontFamily")
			textFormat.bold=getStyle("fontWeight")
			textFormat.align=getStyle("textAlign")
			textField.defaultTextFormat=textFormat;
			this.addChild(textField)
		}

		override protected function updateDisplay(w:int, h:int):void
		{
			skin.updateDisplay(w, h, null);


		}

		override protected function layoutContents(w:int, h:int):void
		{
			adjustTextField();

		}

		private function adjustTextField():void
		{
			textField.autoSize="left"
			var th:Number=textField.height
			textField.autoSize="none"
			textField.width=this.width;
			textField.height=th;
			textField.y=int((height - th) / 2);
		}

		public function get text():String
		{
			return textField.text;
		}

		public function set text(text:String):void
		{
			if (text == null)
			{
				text=""
			}
			textField.text=text;
			adjustTextField();
		}
	}
}
